package com.ruoyi.carService.controller;

import java.util.HashMap;
import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.system.api.domain.OrderCount;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.api.domain.OrderDetails;
import com.ruoyi.carService.service.IOrderDetailsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 订单统计Controller
 * 
 * @author ruoyi
 * @date 2024-09-07
 */
@RestController
@RequestMapping("/orderCount")
public class OrderDetailsController extends BaseController
{
    @Autowired
    private IOrderDetailsService orderDetailsService;

    @RequestMapping("/countdd")
    public Map getTodayOrderCount(){
        Map map = new HashMap();
        map.put("countdd", orderDetailsService.getTodayOrderCount());
        return map;
    }
    @RequestMapping("/sum")
    public Map getTodayPayPriceSum(){
        Map map = new HashMap();
        map.put("sum", orderDetailsService.getTodayPayPriceSum());
        return map;
    }


    /**
     * 查询订单统计列表
     */
    @RequiresPermissions("carService:orderCount:list")
    @GetMapping("/list")
    public TableDataInfo list(String startTime, String endTime)
    {
        startPage();
        List<OrderCount> list = orderDetailsService.selectOrderCountList(startTime,endTime);
        return getDataTable(list);
    }

    /**
     * 导出订单统计列表
     */
    @RequiresPermissions("carService:orderCount:export")
    @Log(title = "订单统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderDetails orderDetails)
    {
        List<OrderDetails> list = orderDetailsService.selectOrderDetailsList(orderDetails);
        ExcelUtil<OrderDetails> util = new ExcelUtil<OrderDetails>(OrderDetails.class);
        util.exportExcel(response, list, "订单统计数据");
    }

    /**
     * 获取订单统计详细信息
     */
    @RequiresPermissions("carService:orderCount:query")
    @GetMapping(value = "/{orderDetailsId}")
    public AjaxResult getInfo(@PathVariable("orderDetailsId") Long orderDetailsId)
    {
        return success(orderDetailsService.selectOrderDetailsByOrderDetailsId(orderDetailsId));
    }

    /**
     * 新增订单统计
     */
    @RequiresPermissions("carService:orderCount:add")
    @Log(title = "订单统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderDetails orderDetails)
    {
        return toAjax(orderDetailsService.insertOrderDetails(orderDetails));
    }

    /**
     * 修改订单统计
     */
    @RequiresPermissions("carService:orderCount:edit")
    @Log(title = "订单统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderDetails orderDetails)
    {
        return toAjax(orderDetailsService.updateOrderDetails(orderDetails));
    }

    /**
     * 删除订单统计
     */
    @RequiresPermissions("carService:orderCount:remove")
    @Log(title = "订单统计", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderDetailsIds}")
    public AjaxResult remove(@PathVariable Long[] orderDetailsIds)
    {
        return toAjax(orderDetailsService.deleteOrderDetailsByOrderDetailsIds(orderDetailsIds));
    }
}
